package com.caiyouxi.finance.service;

import com.caiyouxi.common.Constant;
import com.caiyouxi.common.service.BaseService;
import com.caiyouxi.finance.mapper.FinancePaymentDetailMapper;
import com.caiyouxi.finance.model.FinancePaymentDetail;
import com.caiyouxi.order.model.OrderBean;
import com.caiyouxi.util.NumUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.Date;
import java.util.HashMap;


/**
 * 财务流水记录
 * chensong
 */
@Service
public class FinancePaymentDetailService extends BaseService {
    
    @Autowired
    private FinancePaymentDetailMapper financePaymentDetailMapper;

    public void add_finance_payment_detail(Integer amount,BigInteger ftrdId,Integer buyer_user_id,String payment_detail,String paymentType){
        FinancePaymentDetail fpd = new FinancePaymentDetail();
        fpd.setAmount(amount);
        fpd.setFinance_received_id(ftrdId);
        fpd.setId(new BigInteger(NumUtil.generate_number(3)));
        fpd.setPayer_user_id(buyer_user_id);
        fpd.setPayment_detail(payment_detail);
        fpd.setPayment_type(paymentType);//使用的支付方式 GATEWAY：第三方支付 COUPON：红包、券 ACCOUNT：账户支付
        fpd.setStatus(Constant.ORDER_STATUS_PAIED);//已支付的
        fpd.setCreate_time(new Date());
        financePaymentDetailMapper.add_finance_payment_detail(fpd);
    }

    /**
     * 已享受折扣的商品数量
     * @param payment_type
     * @return
     */
    public OrderBean get_min_by_payment_type_and_payment_detail(String payment_type, Integer goods_discount_id){
        HashMap<String,Object> map = new HashMap();
        map.put("payment_type",payment_type);
        map.put("payment_detail",goods_discount_id.toString());
        return financePaymentDetailMapper.get_min_by_payment_type_and_payment_detail(map);
    }

    public Integer get_sum_by_payment_type_and_payment_detail(String payment_type, Integer goods_discount_id){
        HashMap<String,Object> map = new HashMap();
        map.put("payment_type",payment_type);
        map.put("payment_detail",goods_discount_id.toString());
        return financePaymentDetailMapper.get_sum_by_payment_type_and_payment_detail(map);
    }
}
